package com.aids_malaria.db;


import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.migration.Migration;

import com.aids_malaria.app.App;
import com.aids_malaria.app.AppManager;
import com.aids_malaria.db.dao.AreaCDao;
import com.aids_malaria.db.dao.AreaVDao;
import com.aids_malaria.db.dao.DiagnosisInfoPackDao;
import com.aids_malaria.db.dao.DrugallergyInfoPackDao;
import com.aids_malaria.db.dao.EaProcessPackDao;
import com.aids_malaria.db.dao.GetMedicalTreatmentDao;
import com.aids_malaria.db.dao.GetMedicalTreatmentPackDao;
import com.aids_malaria.db.dao.LoginUserAuthDao;
import com.aids_malaria.db.dao.MosquitoInvestDao;
import com.aids_malaria.db.dao.PadDao;
import com.aids_malaria.db.dao.PadMaxIdentitySeqDao;
import com.aids_malaria.db.dao.PersonDataDao;
import com.aids_malaria.db.dao.PremedicalTreatmentPackDao;
import com.aids_malaria.db.dao.RoleAuthDao;
import com.aids_malaria.db.dao.UserDao;
import com.aids_malaria.db.dao.WorkAreaPersonIDDao;
import com.aids_malaria.db.dao.WorkAreaResponseDao;
import com.aids_malaria.http.response.AreaC;
import com.aids_malaria.http.response.AreaV;
import com.aids_malaria.http.response.DiagnosisInfoPack;
import com.aids_malaria.http.response.DrugallergyInfoPack;
import com.aids_malaria.http.response.EaProcessPack;
import com.aids_malaria.http.response.GetMedicalTreatment;
import com.aids_malaria.http.response.GetMedicalTreatmentPack;
import com.aids_malaria.http.response.LoginUserAuth;
import com.aids_malaria.http.response.MosquitoInvest;
import com.aids_malaria.http.response.Pad;
import com.aids_malaria.http.response.PadMaxIdentitySeq;
import com.aids_malaria.http.response.PersonData;
import com.aids_malaria.http.response.PremedicalTreatmentPack;
import com.aids_malaria.http.response.RoleAuth;
import com.aids_malaria.http.response.User;
import com.aids_malaria.http.response.WorkAreaPersonID;
import com.aids_malaria.http.response.WorkAreaResponse;

@Database(entities = {AreaC.class, DiagnosisInfoPack.class, DrugallergyInfoPack.class, EaProcessPack.class, User.class,
        GetMedicalTreatment.class, GetMedicalTreatmentPack.class, MosquitoInvest.class, Pad.class,PadMaxIdentitySeq.class,
        PersonData.class, PremedicalTreatmentPack.class, RoleAuth.class, WorkAreaPersonID.class, WorkAreaResponse.class, AreaV.class
        , LoginUserAuth.class
        }, version = 3, exportSchema = false)
public abstract class DBManager extends RoomDatabase {
    public abstract UserDao userDao();
    public abstract AreaVDao areaVDao();
    public abstract AreaCDao areaCDao();
    public abstract DiagnosisInfoPackDao diagnosisInfoPackDao();
    public abstract DrugallergyInfoPackDao drugallergyInfoPackDao();
    public abstract EaProcessPackDao eaProcessPackDao();
    public abstract GetMedicalTreatmentDao getMedicalTreatmentDao();
    public abstract GetMedicalTreatmentPackDao getMedicalTreatmentPackDao();
    public abstract MosquitoInvestDao mosquitoInvestDao();
    public abstract PadDao padDao();
    public abstract PadMaxIdentitySeqDao padMaxIdentitySeqDao();
    public abstract PersonDataDao personDataDao();
    public abstract PremedicalTreatmentPackDao premedicalTreatmentPackDao();
    public abstract RoleAuthDao roleAuthDao();
    public abstract WorkAreaPersonIDDao workAreaPersonIDDao();
    public abstract WorkAreaResponseDao workAreaResponseDao();
    public abstract LoginUserAuthDao loginUserAuthDao();

    //数据库变动添加Migration
    static final Migration MIGRATION_1_3 = new Migration(1, 3) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            //数据库更新(workAreaPersonID表添加是否下载标识字段isDownload)
            database.execSQL("ALTER TABLE workAreaPersonID "
                    + " ADD COLUMN isDownload INTEGER");
        }
    };
    private static DBManager dbManager;
    public static DBManager get() {
        if (dbManager == null) {
            synchronized (AppManager.class) {
                if (dbManager == null) {
                    dbManager = Room.databaseBuilder(App.getInstance(),DBManager.class,"aidsma")
                            .allowMainThreadQueries()
                            .addMigrations(MIGRATION_1_3)
                            .fallbackToDestructiveMigration().build();
                }
            }
        }
        return dbManager;
    }


}